<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('海外仓发货申请列表')" />
	<th:block th:include="include :: list-css" />
    <style>
        .layui-tab-title{border-color: #ccc !important;}
        .layui-this{color: rgb(0, 135, 250) !important;background: none !important;}
        .layui-tab-brief > .layui-tab-title .layui-this:after, .layui-tab-brief > .layui-tab-more li.layui-this:after{border-color:  rgb(0, 135, 250) !important;}
        .mid-content {overflow: auto;}
        .layui-tab-content {padding-top: 3px;}
    </style>
</head>
<body class="no-skin">
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn">
			<i class="dhicon dh-lujing1089"></i> 新增
		</div>
		<!--
		<div class="layui-btn layui-btn-normal layui-table-tools" lay-event="editbtn">
			<i class="dhicon dh-edit"></i> 编辑
		</div>-->
		<div class="layui-btn layui-table-tools importbtn-bg shbtn" lay-event="shbtn">
			<i class="dhicon layui-icon-prev"></i> 审核
		</div>
		<div class="layui-btn layui-btn-danger layui-table-tools delbtn" lay-event="deleteBatch" shiro:hasPermission="storage:deliveryRequest:delete">
			<p class="dhicon dh-remove" style="color:white;font-size:14px"><span class="fa_span">批量删除</span></p>
		</div>
        <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="exportbtn">
			<i class="dhicon dh-zu4250_2_2"></i> 导出
		</div>
		<!--
		<div class="layui-btn layui-table-tools importbtn-bg'"
			lay-event="importBatch">
			<i class="dhicon dh-upload"></i> 批量导入
		</div>
		-->

    </div>
</script>
<!--<div class="layui-btn layui-btn-normal layui-table-tools" lay-event="editbtn">
			<i class="dhicon dh-edit"></i> 编辑
		</div>-->
<script type="text/html" id="toolbar2">
	<div class="layui-btn-container">
        <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="exportbtn">
			<i class="dhicon dh-zu4250_2_2"></i> 导出
		</div>
		<div class="layui-btn layui-table-tools importbtn-bg shbtn" lay-event="shbtn">
			<i class="dhicon layui-icon-prev"></i> 审核
		</div>
		<div class="layui-btn layui-table-tools importbtn-bg shbtn" lay-event="refusebtn">
			<i class="dhicon layui-icon-prev"></i> 回退
		</div>
    </div>
</script>

<script type="text/html" id="toolbar3">
	<div class="layui-btn-container">
        <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="exportbtn">
			<i class="dhicon dh-zu4250_2_2"></i> 导出
		</div>
		<div class="layui-btn layui-table-tools importbtn-bg shbtn" lay-event="shbtn">
			<i class="dhicon layui-icon-prev"></i> 审核
		</div>
		<div class="layui-btn layui-table-tools importbtn-bg shbtn" lay-event="refusebtn">
			<i class="dhicon layui-icon-prev"></i> 回退
		</div>
    </div>
</script>

<script type="text/html" id="toolbar4">
	<div class="layui-btn-container">
        <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="exportbtn">
			<i class="dhicon dh-zu4250_2_2"></i> 导出
		</div>
		<div class="layui-btn layui-table-tools importbtn-bg shbtn" lay-event="stockIn">
			<i class="dhicon dh-zu4250_2_2"></i> 入库
		</div>
		<div class="layui-btn layui-table-tools importbtn-bg shbtn" lay-event="stockInBack">
			<i class="dhicon layui-icon-prev"></i> 回退
		</div>
		<div class="layui-btn layui-btn-normal layui-table-tools" lay-event="importWaybillNumber">
			<i class="dhicon dh-zu4250_2_2"></i> 批量导入运单号
		</div>
		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="editWayBillNumber">
			<i class="dhicon layui-icon-prev"></i> 填写运单号
		</div>
		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="editTimeArrivePredict">
			<i class="dhicon layui-icon-prev"></i> 填写到货时间
		</div>
    </div>
</script>
<script th:inline="javascript">
    /*<![CDATA[*/
    var gridColumns = [[${gridColumns}]],
        storage = [[${storage}]],
        buttonState = [[${buttonState}]],
        businessName = gridColumns.moduleAlias,
        passwordAuthentication = [[${passwordAuthentication}]],
        moduleTable = [[${moduleTable}]];
    /*]]>*/
    var prefix = "/storage/"+storage;
	var tableUrl = prefix + "/list",
	openRowUrl = "/storage/"+(storage.split('/')[1]?storage.split('/')[0]:storage)+"/edit?nid=";
	delUrl = prefix+"/delete";
</script>

<div class="mid-content-hw" style="width:100%;">
    <div class="layui-tab layui-tab-brief istype" lay-filter="demo1" style="margin-top: 0;">
        <ul class="layui-tab-title" >
            <li class="layui-this">海外仓发货申请</li>
            <li onclick="doLoadTab(this)" data-loaded="0" data-table="HW_DeliveryBox">海外仓发货装箱</li>
            <li onclick="doLoadTab(this)" data-loaded="0" data-table="HW_DeliveryLogistics">海外仓发货物流</li>
            <li onclick="doLoadTab(this)" data-loaded="0" data-table="HW_DeliveryLogisticsRK">海外仓入库</li>
        </ul>
        <div class="layui-tab-content">
        	<!-- 海外仓发货申请 -->
        	<div class="layui-tab-item layui-show" id="content1">
				<div class="content-right">
					<div class="search-top" >
						<span>查询条件</span>
						<a href="javascript:void(0);" class="menuBtn">
							<i class="layui-icon layui-icon-spread-left" style="color: #fff;"></i>
						</a>
					</div>
					<div class="panel layout-expand layui-expand-east">
						<div class="panel-header">
							<div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
								<a href="javascript:;" layadmin-event="flexible" class="menuBtn">
									<i class="layui-icon layui-icon-shrink-right" style="color: #fff;"></i>
								</a>
							</div>
						</div>
						<div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
					</div>
					<form class="layui-form">
						<th:block th:include="listinclude :: searchRightNew('HW_DELIVERYREQUEST', 'page', 'search1')" />
					</form>
				</div>
		        <div class="mid-content" style="top:55px;" data-sonlist-name="sonlist">
				    <table class="layui-hide" id="dhtable1" lay-filter="ftable1"></table>
			        <div class="spxx" style="display: none;">
			            <div class="layui-tab layui-tab-brief demo1" lay-filter="demo1" style="position:relative;">
			                <ul class="layui-tab-title">
			                    <li class="detailsName">海外仓发货申请-详情</li>
			                </ul>
			                <div class="layui-tab-content"></div>
			            </div>
			            <table class="layui-hide" id="pdhtable1" lay-filter="pftable1"></table>
			        </div>
        	    </div>
        	</div>
        	<!-- 海外仓发货装箱 -->
        	<div class="layui-tab-item" id="content2">
				<div class="content-right">
					<div class="search-top" >
						<span>查询条件</span>
						<a href="javascript:void(0);" class="menuBtn">
							<i class="layui-icon layui-icon-spread-left" style="color: #fff;"></i>
						</a>
					</div>
					<div class="panel layout-expand layui-expand-east">
						<div class="panel-header">
							<div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
								<a href="javascript:;" layadmin-event="flexible" class="menuBtn">
									<i class="layui-icon layui-icon-shrink-right" style="color: #fff;"></i>
								</a>
							</div>
						</div>
						<div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
					</div>
					<form class="layui-form">
						<th:block th:include="listinclude :: searchRightNew('HW_DELIVERYBOX', 'page', 'search2')" />
					</form>
				</div>
		        <div class="mid-content" style="top:55px;" data-sonlist-name="sonlist">
				    <table class="layui-hide" id="dhtable2" lay-filter="ftable2"></table>
			        <div class="spxx" style="display: none;">
			            <div class="layui-tab layui-tab-brief demo2" lay-filter="demo2" style="position:relative;">
			                <ul class="layui-tab-title">
			                    <li class="detailsName">海外仓发货装箱-详情</li>
			                </ul>
			                <div class="layui-tab-content"></div>
			            </div>
			            <table class="layui-hide" id="pdhtable2" lay-filter="pftable2"></table>
			        </div>
        	    </div>
        	</div>
        	<div class="layui-tab-item" id="content3">
				<div class="content-right">
					<div class="search-top" >
						<span>查询条件</span>
						<a href="javascript:void(0);" class="menuBtn">
							<i class="layui-icon layui-icon-spread-left" style="color: #fff;"></i>
						</a>
					</div>
					<div class="panel layout-expand layui-expand-east">
						<div class="panel-header">
							<div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
								<a href="javascript:;" layadmin-event="flexible" class="menuBtn">
									<i class="layui-icon layui-icon-shrink-right" style="color: #fff;"></i>
								</a>
							</div>
						</div>
						<div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
					</div>
					<form class="layui-form">
						<th:block th:include="listinclude :: searchRightNew('HW_DELIVERYLOGISTICS', 'page', 'search3')" />
					</form>
				</div>
		        <div class="mid-content" style="top:55px;" data-sonlist-name="sonlist">
				    <table class="layui-hide" id="dhtable3" lay-filter="ftable3"></table>
			        <div class="spxx" style="display: none;">
			            <div class="layui-tab layui-tab-brief demo3" lay-filter="demo3" style="position:relative;">
			                <ul class="layui-tab-title">
			                    <li class="detailsName">海外仓发货物流-详情</li>
			                </ul>
			                <div class="layui-tab-content"></div>
			            </div>
			            <table class="layui-hide" id="pdhtable3" lay-filter="pftable3"></table>
			        </div>
        	    </div>
        	</div>
        	<div class="layui-tab-item" id="content4">
				<div class="content-right">
					<div class="search-top" >
						<span>查询条件</span>
						<a href="javascript:void(0);" class="menuBtn">
							<i class="layui-icon layui-icon-spread-left" style="color: #fff;"></i>
						</a>
					</div>
					<div class="panel layout-expand layui-expand-east">
						<div class="panel-header">
							<div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
								<a href="javascript:;" layadmin-event="flexible" class="menuBtn">
									<i class="layui-icon layui-icon-shrink-right" style="color: #fff;"></i>
								</a>
							</div>
						</div>
						<div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
					</div>
					<form class="layui-form">
						<th:block th:include="listinclude :: searchRightNew('HW_DELIVERYLOGISTICSRK', 'page', 'search4')" />
					</form>
				</div>
		        <div class="mid-content" style="top:55px;" data-sonlist-name="sonlist">
				    <table class="layui-hide" id="dhtable4" lay-filter="ftable4"></table>
			        <div class="spxx" style="display: none;">
			            <div class="layui-tab layui-tab-brief demo4" lay-filter="demo4" style="position:relative;">
			                <ul class="layui-tab-title">
			                    <li class="detailsName">海外仓发货物流-详情</li>
			                </ul>
			                <div class="layui-tab-content"></div>
			            </div>
			            <table class="layui-hide" id="pdhtable4" lay-filter="pftable4"></table>
			        </div>
        	    </div>
        	</div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: searchJS" />
<th:block th:include="listinclude :: list-templeat" />
<th:block th:include="include :: deliveryRequestJS" />

<script type="text/javascript">
	var element,thStr;
	var fieldWidth = {},		//导入列表字段宽度
			filedRequired = {},		//导入列表必填字段
			dateFiled = [],			//导入列表日期字段
			hasNull = false;		//导入数据必填字段有空值
			
    var $, layer, form, table, laydate, util, laydate, wherestr = {}, moduleUrl;
    var scroll = {X: '', Y: ''};
    var pagenum = 1
    
    layui.use(['table', 'form', 'layer', 'jquery', 'laydate', 'element'], function () {
        $ = layui.$, layer = layui.layer, form = layui.form, table = layui.table, laydate = layui.laydate, element = layui.element;
        serachRender();//查询条件初始渲染集合
        sessionStorage.setItem(moduleTable + 'checkdata', '')
        var isbtn = true
        $.tablelist.init({
            elem: '#dhtable1',
            url: tableUrl,
            where: getWherestr('#search1'),
            totalRow: gridColumns.totalRow,
            cols: [gridColumns.gridBody],
            toolbar: '#toolbar',
            defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}]
            ,height: 'full-80'
            ,done: function (res, curr, count) {
            }
        });

		// 有多少个主表，就要定义多少个表格过滤筛选值
		var filterTable1 = 'ftable1';
		var filterTable2 = 'ftable2';
		var filterTable3 = 'ftable3';
		var filterTable4 = 'ftable4';
        //头工具栏事件
        table.on('toolbar(' + filterTable1 + ')', function (obj) {
            var checkStatus = table.checkStatus('dhtable1');
            switch (obj.event) {
                case 'addbtn'://新增
    				top.layui.index.openTabsPage(prefix+ "/edit", businessName + ' - 新增')
    				break;
				case 'shbtn'://审核
					var datas = checkStatus.data;
					if(datas.length == 0) {
						layer.msg('请选择一条数据');
						break;
					} else if(datas.length > 1) {
						layer.msg('只能选择一条数据');
						break;
					} else {
						$.modal.confirmCom('确定要审核么？',function(result){
							$.post("/storage/deliveryRequest/updateState",{bid: datas[0].bid},function(res){
								layer.msg(res.msg);
								if(res.code==0){
									setTimeout(function(){
										window.location.reload();
									},500)
								 }
					        });
						});
					}
					break;
                case 'exportbtn'://导出
                    $.ajax({
                        url: '/storage/deliveryRequest/export',
                        type: 'GET',
                        data: getWherestr('#search1'),
                        dataType: 'json',
                        beforeSend: function () {
                            showloadings(true);
                        },
                        success: function (result) {
                            if (result.code == 0) {
                                window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
                                parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
                            } else if (result.code == web_status.WARNING) {
                                $.modal.alertWarning(result.msg)
                            } else {
                                $.modal.alertError(result.msg);
                            }
                            showloadings(false);
                        }
                    });
                    break;
                case 'deleteBatch'://删除
					var datas = checkStatus.data;
					if(datas.length == 0) {
						layer.msg('请选择数据');
						break;
					}
					$.modal.confirmCom('确定要删除么？',function(result){
						//var infoItems=JSON.parse(datas)
						$.operate.post('/storage/deliveryRequest/delete',{infoItems:JSON.stringify(datas)},function(result){
							setTimeout(function(){
								table.reload('dhtable1', {page: {curr: 1},where:getWherestr('#search1')});
							}, 1000);
						});
					});
                    break;

                case 'fieldSet'://列设置
                    filedSet(moduleTable);
                    break;
				case 'editbtn':
					var datas = checkStatus.data;
					if(datas.length == 0) {
						layer.msg('请选择一条数据');
						break;
					} else if(datas.length > 1) {
						layer.msg('只能选择一条数据');
						break;
					}
					top.layui.index.openTabsPage('/storage/deliveryRequest/edit?nid=' + datas[0].nid, '海外仓发货申请-编辑')
					break;
            	}

            ;
        });

        //监听工具条
        table.on('tool(' + filterTable1 + ')', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'workday'://工作时间设定——工作日
                    var pd = [];
                    pd.push(data);
                    $.operate.post('/hr/attendanceworkdateset/editworkday', {'attendanceWorkDateSetItems': JSON.stringify(pd)}, function (res) {
                        if (res.code == 0) table.reload('dhtable1');
                    });
                    break;
                default:
                    break;
            }
        });
        //监听排序事件
        table.on('sort(' + filterTable1 + ')', function (obj) {
            $.tablelist.sort('dhtable1', obj);
        });

		//监听排序事件
		table.on('sort(' + filterTable2 + ')', function (obj) {
			$.tablelist.sort('dhtable2', obj);
		});

		//监听排序事件
		table.on('sort(' + filterTable3 + ')', function (obj) {
			$.tablelist.sort('dhtable3', obj);
		});

		//监听排序事件
		table.on('sort(' + filterTable4 + ')', function (obj) {
			$.tablelist.sort('dhtable4', obj);
		});

        //单击选中行
        var comguid,comobj
        table.on('row(' + filterTable1 + ')', function(obj){
            comguid=obj.data.guid
            comobj=obj
            pddata(obj, 1)
        });
        table.on('row(' + filterTable2 + ')', function(obj){
            comguid=obj.data.guid
            comobj=obj
            pddata(obj, 2)
        });
        table.on('row(' + filterTable3 + ')', function(obj){
            comguid=obj.data.guid
            comobj=obj
            pddata(obj, 3)
        });
        table.on('row(' + filterTable4 + ')', function(obj){
            comguid=obj.data.guid
            comobj=obj
            pddata(obj, 4)
        });

		//监听行双击事件
		table.on('rowDouble(' + filterTable1 + ')', function (obj) {
			top.layui.index.openTabsPage('/storage/deliveryRequest/edit?nid=' + obj.data.nid, '海外仓发货申请-编辑');
		});

		//监听行双击事件
		table.on('rowDouble(' + filterTable2 + ')', function (obj) {
			top.layui.index.openTabsPage('/storage/deliveryBox/edit?bid=' + obj.data.bid, '海外仓发货装箱-详情')
		});

		//监听行双击事件
		table.on('rowDouble(' + filterTable3 + ')', function (obj) {
			top.layui.index.openTabsPage('/storage/deliveryLogistics/edit?bid=' + obj.data.bid, '海外仓发货物流-编辑');
		});

		//监听行双击事件

		table.on('rowDouble(' + filterTable4 + ')', function (obj) {
			top.layui.index.openTabsPage('/storage/deliveryLogistics/edit?bid=' + obj.data.bid, '海外仓入库-详情');
		});



        //子列表表格
        function pddata(obj, index){
        	var urlSonlist = '';
        	if (index == 1) {
        		urlSonlist = '/storage/deliveryRequest/sonlist';
        	} else if (index == 2) {
        		urlSonlist = '/storage/deliveryBox/sonlist';
        	} else if (index == 3) {
        		urlSonlist = '/storage/deliveryLogistics/sonlist';
        	} else if (index == 4) {
        		urlSonlist = '/storage/deliveryLogisticsRK/sonlist';
        	}
            var code = obj.data.code;
            $('#content' + index + '>.demo' + index + ' .layui-tab-title li').removeClass('layui-this')
            $('#content' + index + '>.layui-tab-title li').attr('style','background:#fff;color:#666666');
            $('#content' + index + '>.demo' + index + ' .layui-tab-title li').eq(0).addClass('layui-this')
            $.get(urlSonlist, {code:code,bid:obj.data.bid},function(res){
                var datalist=res.data.sonList;
                var gridBody = res.data.gridColumns.gridBody;
                if(index == 1){//申请单-明细的排序关闭
                	for(var i=0;i<gridBody.length;i++){
						gridBody[i].sort = false;
					}
				}
				var cols=[gridBody];

                var totalRow=res.data.gridColumns.totalRow;
            	console.log('cols---', cols);
            	console.log('totalRow---', totalRow);
                $.tablelist.init({
                    elem: '#pdhtable' + index
                    ,data:datalist
                    ,limit: 99999
                    ,where: getWherestr('#search' + index)
                    ,totalRow:totalRow
                    ,cols: cols
                    ,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}]
                    ,page:false
                    // ,height:moduleTable==''?'full-46':''
                    ,parseData: function(res){ //res 即为原始返回的数据
                        return {
                            "code": res.code, //解析接口状态
                            "msg": res.msg, //解析提示文本
                            "count": res.count, //解析数据长度
                            "data": decimalToFixed(res.data,gridColumns.decimalObj) //表格数据数值类型重赋值
                        }
                    }
                    ,done:function(res, curr, count){
						var ltv=this.elem.next('.layui-table-view');//当前table的dom
						res.data.length || count || ltv.find('.layui-table-header').css('display', 'inline-block');//数量为0时(统计报表存在不传count的情况)，表头赋予样式可拉动
						res.data.length || count || ltv.find('.layui-table-box').css('overflow-x', 'auto');//数量为0时(统计报表存在不传count的情况)，表头赋予样式可拉动
						res.data.length || count || ltv.find('.layui-table-body').css('height', ltv.find('.layui-table-body').height()-17);//数量为0时，表格高度减少滚动条高度

                    	var domContent = $('#content' + index);
						domContent.find('.spxx').show()
						domContent.find('.layui-table-body.layui-table-main').eq(0).css('height', "35vh");
						domContent.find('.layui-table-body.layui-table-main').eq(1).css('height', "30vh");
						domContent.find('.layui-table-body').eq(0).css('height', "35vh");
						domContent.find('.layui-table-view').eq(0).css('height', "45vh");
						domContent.find('.layui-table-body').eq(1).css('height', "calc(35vh - 15px)");
						fixTotal(this);//修复合计行固定列问题
						if(typeof listTableDone == 'function')listTableDone();//如果查询列表存在表格加载完成回调事件，则执行
						if(index == 1){
							/**
							 * 参数1  需要合并列的数组，0代表的是合并单选按钮或者是复选框 radio/checkbox 后端需要将这些字段进行排序
							 * 参数2  当前表格的index (用于在一个页面中有使用了多个表格的情况，如果只有一个表格填0就行
							 * 		  index这个值是表格加载的顺序，从0开始，如果页面上表格很多建议debug用 $(".layui-table-body")[index]看一下就拿到了)
							 * 参数3  是按照html元素合并，还是按照标签中的text内容合并，建议填true
							 * 参数4  radio/checkbox根据哪一行去合并
							 */
							//合并单元格
							layuiRowspan([ 'commodityCode', 'name', 'numBox', 'numSingleBox', 'numCommodity', 'volume', 'weight', 'productNameCn', 'productMaterialCn', 'productCodeHs'], "2", true, "commodityCode");
						}
                    }
                    ,jump:function(obj, first){
                    }
                })
            })
        }
        
    	//搜索按钮1
    	$('#search1-btn').on('click', function () {
    		sessionStorage.removeItem(moduleTable + 'checkdata');
    		table.reload('dhtable1', {page: {curr: 1},where:getWherestr('#search1')});
    	});
    	//搜索按钮2
    	$('#search2-btn').on('click', function () {
    		sessionStorage.removeItem(moduleTable + 'checkdata');
    		table.reload('dhtable2', {page: {curr: 1},where:getWherestr('#search2')});
    	});
    	//搜索按钮3
    	$('#search3-btn').on('click', function () {
    		sessionStorage.removeItem(moduleTable + 'checkdata');
    		table.reload('dhtable3', {page: {curr: 1},where:getWherestr('#search3')});
    	});
    	//搜索按钮4
    	$('#search4-btn').on('click', function () {
    		sessionStorage.removeItem(moduleTable + 'checkdata');
    		table.reload('dhtable4', {page: {curr: 1},where:getWherestr('#search4')});
    	});

    	// 搜索框折叠/展开
    	var domRoot2 = $('#content2');
    	initSearchMenu(domRoot2);

    	// 搜索框折叠/展开
    	var domRoot3 = $('#content3');
    	initSearchMenu(domRoot3);


    })
    
	// 加载tab数据
    function doLoadTab(obj) {
    	var dom = $(obj);
    	var dataLoaded = dom.attr('data-loaded');
    	// 若已加载过，则不需要继续加载
    	if(dataLoaded == 1) {
    		return;
    	}
    	// 将属性设置为已加载
    	dom.attr('data-loaded', 1)
    	
    	var dataTable = dom.attr('data-table');
    	
    	var urlConfig = '';
    	if (dataTable == 'HW_DeliveryBox') {
    		urlConfig = '/storage/deliveryBox/indexConfig';
    	} else if (dataTable == 'HW_DeliveryLogistics') {
    		urlConfig = '/storage/deliveryLogistics/indexConfig';
    	} else if (dataTable == 'HW_DeliveryLogisticsRK') {
    		urlConfig = '/storage/deliveryLogisticsRK/indexConfig';
    	}
   		$.ajax({
   		    url: urlConfig,
   		    type: 'GET',
   		    data: {},
   		    dataType: 'json',
   		    beforeSend: function(){
	   			showloadings(true);
   		    },
   		    success: function(result){
   		    	if(result.code == 0) {
   	   		    	var data = result.data;
   	   		    	
   	   		    	if(dataTable == 'HW_DeliveryBox') {
   	   	   		    	
   	   	   		        $.tablelist.init({
   	   	   		            elem: '#dhtable2',
   	   	   		            url: '/storage/deliveryBox/list',
   	   	   		            where: getWherestr('#search2'),
   	   	   		            totalRow: data.gridColumns.totalRow,
   	   	   		            cols: [data.gridColumns.gridBody],
   	   	   		            toolbar: '#toolbar2',
   	   	   		            defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}]
   	   	   		            ,height: 'full-80'
   	   	   		            ,done: function (res, curr, count) {
   	   	   		            }
   	   	   		        });
						//头工具栏事件
						var filterTable2 = 'ftable2';
						table.on('toolbar(' + filterTable2 + ')', function (obj) {
							var checkStatus = table.checkStatus('dhtable2');
							switch (obj.event) {
				                case 'exportbtn'://导出
				                    $.ajax({
				                        url: '/storage/deliveryBox/export',
				                        type: 'GET',
				                        data: getWherestr('#search2'),
				                        dataType: 'json',
				                        beforeSend: function () {
				                            showloadings(true);
				                        },
				                        success: function (result) {
				                            if (result.code == 0) {
				                                window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
				                                parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
				                            } else if (result.code == web_status.WARNING) {
				                                $.modal.alertWarning(result.msg)
				                            } else {
				                                $.modal.alertError(result.msg);
				                            }
				                            showloadings(false);
				                        }
				                    });
				                    break;
								case 'editbtn': // 编辑
									var datas = checkStatus.data;
									if(datas.length == 0) {
										layer.msg('请选择一条数据');
										break;
									} else if(datas.length > 1) {
										layer.msg('只能选择一条数据');
										break;
									}
									top.layui.index.openTabsPage('/storage/deliveryBox/edit?bid=' + datas[0].bid, '海外仓发货装箱-编辑')
									break;
								case 'fieldSet'://列设置
									filedSet(dataTable);
									break;
								case 'shbtn'://审核
									var datas = checkStatus.data;
									if(datas.length == 0) {
										layer.msg('请选择一条数据');
										break;
									} else if(datas.length > 1) {
										layer.msg('只能选择一条数据');
										break;
									} else {
										$.modal.confirmCom('确定要审核么？',function(result){
											$.post("/storage/deliveryBox/updateState",{bid: datas[0].bid},function(res){
												layer.msg(res.msg);
												if(res.code==0){
													setTimeout(function(){
														window.location.reload();
													},500)
												 }
									        });
										});
									}
									break;
								case 'refusebtn'://回退
									var datas = checkStatus.data;
									if(datas.length == 0) {
										layer.msg('请选择一条数据');
										break;
									} else if(datas.length > 1) {
										layer.msg('只能选择一条数据');
										break;
									} else {
										$.modal.confirmCom('确定要回退么？',function(result){
											$.post("/storage/deliveryBox/refuse",{bid: datas[0].bid},function(res){
												layer.msg(res.msg);
												if(res.code==0){
													setTimeout(function(){
														window.location.reload();
													},500)
												 }
									        });
										});
									}
									break;
							}
						});
					} else if(dataTable == 'HW_DeliveryLogistics') {
   	   	   		    	
   	   	   		        $.tablelist.init({
   	   	   		            elem: '#dhtable3',
   	   	   		            url: '/storage/deliveryLogistics/list',
   	   	   		            where: getWherestr('#search3'),
   	   	   		            totalRow: data.gridColumns.totalRow,
   	   	   		            cols: [data.gridColumns.gridBody],
   	   	   		            toolbar: '#toolbar3',
   	   	   		            defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}]
   	   	   		            ,height: 'full-80'
   	   	   		            ,done: function (res, curr, count) {
   	   	   		            }
   	   	   		        });
   	   	   		        
						//头工具栏事件
						var filterTable3 = 'ftable3';
						table.on('toolbar(' + filterTable3 + ')', function (obj) {
							var checkStatus = table.checkStatus('dhtable3');
							switch (obj.event) {
				                case 'exportbtn'://导出
				                    $.ajax({
				                        url: '/storage/deliveryLogistics/export',
				                        type: 'GET',
				                        data: getWherestr('#search3'),
				                        dataType: 'json',
				                        beforeSend: function () {
				                            showloadings(true);
				                        },
				                        success: function (result) {
				                            if (result.code == 0) {
				                                window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
				                                parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
				                            } else if (result.code == web_status.WARNING) {
				                                $.modal.alertWarning(result.msg)
				                            } else {
				                                $.modal.alertError(result.msg);
				                            }
				                            showloadings(false);
				                        }
				                    });
				                    break;
								case 'editbtn': // 编辑
									var datas = checkStatus.data;
									if(datas.length == 0) {
										layer.msg('请选择一条数据');
										break;
									} else if(datas.length > 1) {
										layer.msg('只能选择一条数据');
										break;
									}
									top.layui.index.openTabsPage('/storage/deliveryLogistics/edit?bid=' + datas[0].bid, '海外仓发货物流-编辑')
									break;
								case 'fieldSet'://列设置
									filedSet(dataTable);
									break;
								case 'shbtn'://审核
									var datas = checkStatus.data;
									if(datas.length == 0) {
										layer.msg('请选择一条数据');
										break;
									} else if(datas.length > 1) {
										layer.msg('只能选择一条数据');
										break;
									} else {
										$.modal.confirmCom('确定要审核么？',function(result){
											$.post("/storage/deliveryLogistics/updateState",{bid: datas[0].bid},function(res){
												layer.msg(res.msg);
												if(res.code==0){
													setTimeout(function(){
														window.location.reload();
													},500)
												 }
									        });
										});
									}
									break;
								case 'refusebtn'://回退
									var datas = checkStatus.data;
									if(datas.length == 0) {
										layer.msg('请选择一条数据');
										break;
									} else if(datas.length > 1) {
										layer.msg('只能选择一条数据');
										break;
									} else {
										$.modal.confirmCom('确定要回退么？',function(result){
											$.post("/storage/deliveryLogistics/refuse",{bid: datas[0].bid},function(res){
												layer.msg(res.msg);
												if(res.code==0){
													setTimeout(function(){
														window.location.reload();
													},500)
												 }
									        });
										});
									}
									break;
							}
						});
   	   		    	} else if(dataTable == 'HW_DeliveryLogisticsRK') {
   	   	   		    	
   	   	   		        $.tablelist.init({
   	   	   		            elem: '#dhtable4',
   	   	   		            url: '/storage/deliveryLogisticsRK/list',
   	   	   		            where: getWherestr('#search4'),
   	   	   		            totalRow: data.gridColumns.totalRow,
   	   	   		            cols: [data.gridColumns.gridBody],
   	   	   		            toolbar: '#toolbar4',
   	   	   		            defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}]
   	   	   		            ,height: 'full-80'
   	   	   		            ,done: function (res, curr, count) {
   	   	   		            }
   	   	   		        });
   	   	   		        
						//头工具栏事件
						var filterTable4 = 'ftable4';
						table.on('toolbar(' + filterTable4 + ')', function (obj) {
							var checkStatus = table.checkStatus('dhtable4');
							switch (obj.event) {
								case 'fieldSet'://列设置
									filedSet(dataTable);
									break;
				                case 'exportbtn'://导出
				                    $.ajax({
				                        url: '/storage/deliveryLogisticsRK/export',
				                        type: 'GET',
				                        data: getWherestr('#search4'),
				                        dataType: 'json',
				                        beforeSend: function () {
				                            showloadings(true);
				                        },
				                        success: function (result) {
				                            if (result.code == 0) {
				                                window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
				                                parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
				                            } else if (result.code == web_status.WARNING) {
				                                $.modal.alertWarning(result.msg)
				                            } else {
				                                $.modal.alertError(result.msg);
				                            }
				                            showloadings(false);
				                        }
				                    });
				                    break;
								case 'stockIn'://入库
									var datas = checkStatus.data;
									if(datas.length == 0) {
										layer.msg('请选择一条数据');
										break;
									} else if(datas.length > 1) {
										layer.msg('只能选择一条数据');
										break;
									} else {
										var w=($(window).width()*0.9);
										var h=($(window).height() - 50);
										layer.open({
											type: 2,
											area: [w+'px', h +'px'],
											fix: true,
											maxmin: false,
											shadeClose: true,
											shade:0.4,
											title: "海外仓入库",
											content: '/storage/deliveryLogisticsRK/toStockIn?bid=' + datas[0].bid
										});
									}
									break;
								case 'stockInBack'://回退
									var datas = checkStatus.data;
									if(datas.length == 0) {
										layer.msg('请选择一条数据');
										break;
									} else if(datas.length > 1) {
										layer.msg('只能选择一条数据');
										break;
									} else {
										$.modal.confirmCom('确定要回退么？',function(result){
											$.post("/storage/deliveryLogisticsRK/stockInBack",{bid: datas[0].bid},function(res){
												layer.msg(res.msg);
												if(res.code==0){
													setTimeout(function(){
														window.location.reload();
													},500)
												 }
									        });
										});
									}
									break;
				                case 'importWaybillNumber':// 批量导入运单号
				                	var w=($(window).width()*0.8);
				                	var h=($(window).height() - 100);
				            		layer.open({
				            			type: 2,
				            			area: [w+'px', h +'px'],
				            			fix: true,
				            			maxmin: false,
				            			shadeClose: true,
				            			shade:0.4,
				            			title: "批量导入",
				            			content: '/storage/deliveryLogisticsRK/toImportBatch'
				            		});

				                    break;
								case 'editWayBillNumber'://填写运单号
									var datas = checkStatus.data;
									if(datas.length == 0) {
										layer.msg('请选择一条数据');
										break;
									} else if(datas.length > 1) {
										layer.msg('只能选择一条数据');
										break;
									} else {
					                    layer.prompt({title: '请输入运单号', formType: 0}, function (text, index) {
					                        $.post('/storage/deliveryLogisticsRK/editWayBillNumber', {
					                            'bid': datas[0].bid,
					                            wayBillNumber: text
					                        }, function (res) {
												layer.msg(res.msg);
					                            setTimeout(function () {
					                            	layer.close(index);
					                                table.reload('dhtable4', {page: {curr: 1}, where: getWherestr()});
					                            }, 1000);
					                        });
					                    });
									}
									break;
								case 'editTimeArrivePredict'://填写到货时间
									var datas = checkStatus.data;
									if(datas.length == 0) {
										layer.msg('请选择一条数据');
										break;
									} else if(datas.length > 1) {
										layer.msg('只能选择一条数据');
										break;
									} else {
					                    layer.prompt({title: '请选择到货时间', formType: 0, id:'prompt_TimeArrivePredict'}, function (text, index) {
					                        $.post('/storage/deliveryLogisticsRK/editTimeArrivePredict', {
					                            'bid': datas[0].bid,
					                            timeArrivePredict: text
					                        }, function (res) {
												layer.msg(res.msg);
					                            setTimeout(function () {
					                            	layer.close(index);
					                                table.reload('dhtable4', {page: {curr: 1}, where: getWherestr()});
					                            }, 1000);
					                        });
					                    });
										var indexOfLoading = layer.load(1, {
											shade: [0.5,'#000000'] //0.1透明度的白色背景
										});
										
										//初始化搜索框-日期限定一天
										lay('#prompt_TimeArrivePredict input[type="text"]').each(function(){
											$(this).attr('readonly', 'readonly');
											laydate.render({
												elem: this
												, type: 'date'
												, calendar: true
												, btns: ['clear', 'confirm', 'now']
												, done: function (value, date) {
													//这里时选中后触发事件
													//value是选中的值
													var time = value;
												}
											});
											layer.close(indexOfLoading);
										});
					                }
									break;
							}
						});
   	   		    	}
   		    	}
		   		showloadings(false);
   		    }
   		});
    	return;
    }



</script>

</body>
</html>